const servicesModel = require('../model/servicesModel');
require("../model/adminModel");
require("../model/shopsModel");

// 查询分页服务
module.exports.findAll = async function (searchObj, page) {
    let { current, size } = page;
    let total = await servicesModel.countDocuments(searchObj);
    let totalPage = Math.ceil(total / size);
    let rows = await servicesModel.find(searchObj).populate("shopsModel").populate("adminModel")
        .limit(parseInt(size)).skip((current - 1) * size);
    return { current, size, total, totalPage, rows };
}

// 增加服务
module.exports.insert = async function (services) {
    return await servicesModel.create(services);
}


//修改
module.exports.update = async function (id, obj) {
    try {
        return await servicesModel.updateOne({ _id: id }, obj);
    } catch (e) {
        console.log(e)
        return {}
    }
}

// 根据ID删除服务
module.exports.delete = async function (id) {
    try {
        return await servicesModel.deleteOne({ _id: id });
    } catch (e) {

        return {};
    }
}

